var form = document.querySelector('form')
var username = document.querySelector('[name="username" ]')
var password = document.querySelector('[name=password]')
form.onsubmit = function () {
    var reg = /^[a-z0-9]\w{4,11}$/
    if (!reg.test(user.value)) {
        layer.msg('用户名输入不规范', {
             icon: 2,
             Time: 1500
        })
        return false
    }
    var reg = /\w{6,12}/
    if (!reg.test(password.value)) {
        layer.msg('密码输入不规范',{
            icon: 2,
            time: 1500
        } )
        return false
    }
    promiseAjax({
        url: 'http://localhost:8888/users/login',
        method: 'post',
        data: {
            username: username.value,
            password: password.value,
        },
    }).then(res=>{
        res = JSON.parse(res)
        console.log(res)
        var {message, code} = res
        if(res.code === 1){
            layer.msg(message,{
                icon: 1,
                time: 1500
            },function(){
                localStorage.setItem('id',res.user.id)
                localStorage.setItem('token',res.token)
                var url =localStorage.getItem('url')
                if(url){
                    localStorage.removeItem('url')
                    location.href = url
                }else{
                    location.href = './home.html'
                }
            })
        }else{
            layer.msg(message,{
                icon: 2,
                time: 1500
            })
        }
    })
    return false
}
$('.formTop>p').hover(function(){
    $(this).css('color','#f10783')
},function(){
    $(this).css('color','black')
})
$('.formTop>p').click(function(){
    $(this).parent().next().children().eq($(this).index()).addclass('active').siblings().removeClass('active')

})
$('.bigBox ul li:eq(3)').click(function(){
    $("#div1").fadeToggle(500);
});
$('.formBox ul li:eq(3)').click(function(){
    $("#div2").fadeToggle(500);
});